package com.kevin.util;


import javax.servlet.http.Cookie;

import org.nutz.lang.Mirror;

public class Function{
	public static Object getValue(Object o, String m)   throws Exception{
//    	Class c = o.getClass();
//    	Method method = null;
//    	try {
//      	method = c.getMethod("get" + firstUpper(m), new Class[0]); } catch (Exception localException) {
//    	}
//    	try {
//      	method = c.getMethod("is" + firstUpper(m), new Class[0]); } catch (Exception localException1) {
//    	}
//    	if (method == null) throw new Exception("not method.");
//    	return method.invoke(o, new Object[0]);
		Mirror<?> mirror = Mirror.me(o.getClass());
		return mirror.getValue(o, m);  
    
	}
	public static String firstUpper(String value) {
		char[] tem = value.toCharArray();
		tem[0] = value.toUpperCase().charAt(0);
		return new String(tem);
	}

	public static String getCookieValue(Cookie[] cookies, String cookiename) {
	    try {
	    	for (int i = 0; i < cookies.length; i++)
	    	if (cookies[i].getName().equals(cookiename))
	    		return cookies[i].getValue().trim();
	    }catch (Exception localException) {
	    }
	    return null;
	}
}